package com.hnevc.xiaoming.worldcupapp2018.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;

import com.google.gson.Gson;
import com.hnevc.xiaoming.worldcupapp2018.R;
import com.hnevc.xiaoming.worldcupapp2018.adapter.PaiHangAdapter;
import com.hnevc.xiaoming.worldcupapp2018.bean.AllBean;
import com.hnevc.xiaoming.worldcupapp2018.bean.PhBean;
import com.hnevc.xiaoming.worldcupapp2018.util.GetJsonfileUtil;

import java.util.ArrayList;
import java.util.List;

public class MyPaiHangActivity extends AppCompatActivity {

    private ImageView back;
    private List<PhBean.ItemBean> list;
    private PaiHangAdapter adapter;
    private ListView lv_pai_hang;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_pai_hang);
        list = new ArrayList<>();
        initView();
        initDate();

    }

    private void initDate() {

        String json = new GetJsonfileUtil().getJson(MyPaiHangActivity.this, "allqiudui.json");
        String json2 = new GetJsonfileUtil().getJson(MyPaiHangActivity.this, "paihang.json");

        Gson gson = new Gson();
        AllBean allBean = gson.fromJson(json, AllBean.class);
        PhBean phBean = gson.fromJson(json2, PhBean.class);

        for (int j = 0; j < phBean.getItem().size(); j++) {
            for (int i = 0; i < allBean.getItem().size(); i++) {
                if (phBean.getItem().get(j).getNation().equals(allBean.getItem().get(i).getTeamName())) {
                    phBean.getItem().get(j).setTeamPic(allBean.getItem().get(i).getTeamPic());
                    list.add(phBean.getItem().get(j));
                }
            }
        }

        adapter = new PaiHangAdapter(list, MyPaiHangActivity.this);
        lv_pai_hang.setAdapter(adapter);
    }

    private void initView() {
        back = (ImageView) findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        lv_pai_hang = (ListView) findViewById(R.id.lv_pai_hang);
    }
}
